package info.webest.media.category;

import info.webest.media.Options;
import info.webest.media.R;
import info.webest.media.activities.MainActivity;
import info.webest.media.category.Category.CategoryFolder;
import info.webest.media.category.Category.StorageType;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CategoryAdapter extends ArrayAdapter<String> {
	private final Context context;
	private final String[] values;

	public CategoryAdapter(Context context, String[] values) {
		super(context, R.layout.list_item_with_icon, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View rowView = inflater.inflate(R.layout.list_item_with_icon, parent,
				false);
		TextView tvLabel = (TextView) rowView.findViewById(R.id.tvLabel);
		ImageView ivIcon = (ImageView) rowView.findViewById(R.id.ivIcon);
		tvLabel.setText(values[position]);

		// Change icon based on name
		String s = values[position];

		System.out.println(s);

		int color = MainActivity.getInstance().getResources()
				.getColor(R.color.selected_text);

		switch (Options.Theme) {
		case THEME_DARK:
		default:
			switch (position) {
			case 0:
				ivIcon.setImageResource(R.drawable.ic_menu_card_dark);
				if (Options.HomeStorage == StorageType.INTERNAL_STORAGE) {
					tvLabel.setTextColor(color);
				}
				break;

			case 1:
				ivIcon.setImageResource(R.drawable.ic_menu_card_dark);
				if (Options.HomeStorage == StorageType.EXTERNAL_STORAGE) {
					tvLabel.setTextColor(color);
				}
				break;

			case 2:
				ivIcon.setImageResource(R.drawable.ic_menu_image_picture_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_IMAGE_PICTURE) {
					tvLabel.setTextColor(color);
				}
				break;

			case 3:
				ivIcon.setImageResource(R.drawable.ic_menu_image_screenshot_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_IMAGE_SCREENSHOTE) {
					tvLabel.setTextColor(color);
				}
				break;

			case 4:
				ivIcon.setImageResource(R.drawable.ic_menu_image_camera_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_IMAGE_CAMERA) {
					tvLabel.setTextColor(color);
				}
				break;

			case 5:
				ivIcon.setImageResource(R.drawable.ic_menu_audio_music_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_AUDIO_MUSIC) {
					tvLabel.setTextColor(color);
				}
				break;

			case 6:
				ivIcon.setImageResource(R.drawable.ic_menu_audio_radio_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_AUDIO_RADIO) {
					tvLabel.setTextColor(color);
				}
				break;

			case 7:
				ivIcon.setImageResource(R.drawable.ic_menu_audio_book_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_AUDIO_BOOK) {
					tvLabel.setTextColor(color);
				}
				break;

			case 8:
				ivIcon.setImageResource(R.drawable.ic_menu_audio_recording_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_AUDIO_RECORDING) {
					tvLabel.setTextColor(color);
				}
				break;

			case 9:
				ivIcon.setImageResource(R.drawable.ic_menu_video_movies_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_VIDEO_MOVIE) {
					tvLabel.setTextColor(color);
				}
				break;

			case 10:
				ivIcon.setImageResource(R.drawable.ic_menu_other_download_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_OTHER_DOWNLOAD) {
					tvLabel.setTextColor(color);
				}
				break;

			case 11:
				ivIcon.setImageResource(R.drawable.ic_menu_other_bluetooth_dark);
				if (Options.HomeFolder == CategoryFolder.FOLDER_OTHER_BLUETOOTH) {
					tvLabel.setTextColor(color);
				}
				break;
			}
			break;

		case THEME_LIGHT:
			switch (position) {
			case 0:
				ivIcon.setImageResource(R.drawable.ic_menu_card);
				if (Options.HomeStorage == StorageType.INTERNAL_STORAGE) {
					tvLabel.setTextColor(color);
				}
				break;

			case 1:
				ivIcon.setImageResource(R.drawable.ic_menu_card);
				if (Options.HomeStorage == StorageType.EXTERNAL_STORAGE) {
					tvLabel.setTextColor(color);
				}
				break;

			case 2:
				ivIcon.setImageResource(R.drawable.ic_menu_image_picture);
				break;

			case 3:
				ivIcon.setImageResource(R.drawable.ic_menu_image_screenshot);
				break;

			case 4:
				ivIcon.setImageResource(R.drawable.ic_menu_image_camera);
				break;

			case 5:
				ivIcon.setImageResource(R.drawable.ic_menu_audio_music);
				break;

			case 6:
				ivIcon.setImageResource(R.drawable.ic_menu_audio_radio);
				if (Options.HomeFolder == CategoryFolder.FOLDER_AUDIO_RADIO) {
					tvLabel.setTextColor(color);
				}
				break;

			case 7:
				ivIcon.setImageResource(R.drawable.ic_menu_audio_book);
				break;

			case 8:
				ivIcon.setImageResource(R.drawable.ic_menu_audio_recording);
				break;

			case 9:
				ivIcon.setImageResource(R.drawable.ic_menu_video_movies);
				break;

			case 10:
				ivIcon.setImageResource(R.drawable.ic_menu_other_download);
				break;

			case 11:
				ivIcon.setImageResource(R.drawable.ic_menu_other_bluetooth);
				break;
			}
			break;

		}

		return rowView;
	}
}